package com.googlecode.protoserv.samples;

import com.googlecode.protoserv.JettyRpcServer;
import com.googlecode.protoserv.RpcHandler;
import com.googlecode.protoserv.RpcManager;
import com.googlecode.protoserv.samples.CalcResponse.Builder;

public class CalcServer implements CalcService {

  @Override
  public void add(RpcHandler rpc, BinaryRequest request, Builder response) {
    response.setValue(request.getX() + request.getY());
  }

  @Override
  public void sub(RpcHandler rpc, BinaryRequest request, Builder response) {
    response.setValue(request.getX() - request.getY());
  }

  @Override
  public void sqrt(RpcHandler rpc, UnaryRequest request, Builder response) {
    response.setValue(Math.sqrt(request.getX()));
  }

  public static void main(String[] args) throws Exception {
    RpcManager rpcman = new RpcManager();
    rpcman.register(new CalcServiceSkeleton(new CalcServer()));
    JettyRpcServer.serve(8080, "/*", rpcman);
  }
}
